<?php
namespace console\controllers;

use common\models\Code;
use common\models\Phone;
use common\service\ExcelService;
use common\service\SmsService;
use PhpOffice\PhpSpreadsheet\IOFactory;
use yii\console\Controller;
use yii\db\Query;

class QueueController extends Controller
{
    /**
     * 调用方式　php yii queue/sms
     * 队列　发送短信验证码
     */
    public function actionSms(){
        $data = Code::find()
            ->where(['status'=>0])
            ->limit(10)
            ->orderBy(['time'=>SORT_DESC])
            ->all();
        if(count($data) > 0){
            foreach ($data as $val){
                if(SmsService::sendSms($val['phone'],$val['code'])){
                    $val['status'] = 1;
                    $val->save();
                }
            }
        }
        return true;
    }

}